package logic

import (
	"context"
	car_rpc "week_three/car_srv/proto"
	"week_three/car_srv/service/mysql"
)

func (c *CarRpc) Type(ctx context.Context, in *car_rpc.TypeReq) (*car_rpc.TypeRes, error) {
	CarList, err := mysql.GetCarTypeAll(0)
	if err != nil {
		return &car_rpc.TypeRes{}, err
	}
	var list []*car_rpc.TypeData
	for _, v := range CarList {
		var data = &car_rpc.TypeData{
			Id:    uint32(v.ID),
			Title: v.Title,
			Pid:   int32(v.Pid),
		}
		list = append(list, data)
	}
	return &car_rpc.TypeRes{Data: list}, nil
}
